package uk.ac.cam.djjb2.mygame;

import java.io.DataInput;
import java.io.IOException;

public class ClientTileMapProxy extends ClientReplicaBase {
	private final TileMap target;
	
	public ClientTileMapProxy(ClientReplicaManager replicaManager, int id,
			DataInput message, TileMap target) throws IOException {
		super(replicaManager, id, message);

		this.target = target;
		
		Vector2i size = Vector2i.read(message);
		target.clear(size);
	}
	
	public TileMap getTarget() {
		return target;
	}

	@Override
	public void update(DataInput message) throws IOException,
			InvalidMessageException {

		super.update(message);
		
		int num = message.readInt();
		for (int i = 0; i < num; i++) {
			target.setTileId(Vector2i.read(message), message.readInt());
		}
	}
	
	@Override
	public void destroy(DataInput message) throws IOException,
			InvalidMessageException {
		
		target.clear(Vector2i.ZERO);
		
		super.destroy(message);
	}
}
